<%@ page contentType="text/html; charset=UTF-8"%>
<%@ page import="java.util.*"%>
<%@ page import="com.tera.sys.model.*"%>
<%@ include file="/WEB-INF/jsp/sys/include.jsp"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<base href="<%=basePath%>"/>
<title>Tera</title>
<link href="css/menu.css" type="text/css" rel="stylesheet"/>
<script src="js/jquery-1.5.1.min.js" type="text/javascript"></script>
<style type="text/css">
<!--
body{
	background-color:#e6eef9;
	margin:0px; 
	padding:0px;
}
-->
</style>
<script language="javascript">
function setMenuPath(pathStr){
	
window.parent.topFrame.document.getElementById("menuPathId").innerText=pathStr;
}

</script>
</head>
<body >
<%--
<div id="top"></div>
 --%>
<div id="body">
<%
List menus = (List) request.getSession().getAttribute("menus");

String origCitem = "<a id='expand_link' href='javascript:setModeflag(); '><u><span id='expand_text'>单选</span></u></a>";
String origUlSta="<ul id='menu'>";
String origMenuContent="<!--"+"1"+"-->";//id_level
String origUlEnd="</ul>";

String origination = origCitem + "\n" + origUlSta + "\n" + origMenuContent + "\n" + origUlEnd;
StringBuffer menuContent = new StringBuffer(origination);
for (int i = 1; i < menus.size(); i++) {
	menuContent = menuBuilder((Menu)menus.get(i), menuContent);
}
out.println(menuContent.toString());

%>

<%!
StringBuffer menuBuilder(Menu menu,StringBuffer menuStr){
	String menuItem_P = "<li class='L" + menu.getMenuLevel() + "" + (menu.getMenuLevel()==1?"":"1") + "'><a href='javascript:void(0);' id='m" + menu.getId() + "'><span>" + menu.getName() + "</span></a></li>" + "\n"
	   + "<ul id='m" + menu.getId() + "d' style='display:none;' " + (menu.getMenuLevel()==1?"class='U1'":"") + ">" + "\n"
	   + "<!--" + menu.getId() + "-->" + "\n"
	   + "</ul>" + "\n"
	   + "<!--" + menu.getParentID() + "-->" + "\n";

	String menuItem_L = "<li class='L" + menu.getMenuLevel() + "2'><a href='" + menu.getUrl() + "' onclick=\"javascript:setMenuPath('" + menu.getMenuPath() + "');\" id='f" + menu.getId() + "' target='mainFrame'><span style=''><img class='dotcss' src='img/dot.gif'/>" + menu.getName() + "</span></a></li>" + "\n"
	   + "<!--" + menu.getParentID() + "-->" + "\n";

	String worker = "<!--" + menu.getParentID() + "-->";
	String temp = menuStr.toString();
	//System.out.println(worker + "\n");
	if (null != menu.getUrl()) {
		temp = temp.replaceFirst(worker, menuItem_L);
	} else {
		temp = temp.replaceFirst(worker, menuItem_P);
	}
	return new StringBuffer(temp);
}

%>
	${menuContent}
</div>
</body>
<%--
<div id="bottom"></div>
 --%>
  <script>
  //
  var modeflag = 1;
  
  function setModeflag(){
	  var myspan = document.getElementById("expand_text");
	  if(modeflag==1){
		  modeflag=0;
		  myspan.innerHTML="多选";
	  }else{
		  modeflag=1;
		  myspan.innerHTML="单选";
	  }
  }

$(document).ready(function(){
	 
	
	var citem = $("li[class$='1']");
	for(var ci=0;ci<citem.length; ci++){
		
		$(citem[ci]).children().click(function(){
		
			var targetId = $(this).attr('id')+'d';
	
			if($('#'+targetId).css('display')=='none')
			{
				$(this).attr('class','active');
				$('#'+targetId).css('display','');
			}else{
				$(this).attr('class','');
				$('#'+targetId).css('display','none');
			
			}
			//菜单显示模式
			//alert($(citem).parent().attr('class'));
			if('L1' == $(this).parent().attr('class') && modeflag == 1){
				
				var itemL1 = $(".L1");
				for(var i=0;i<itemL1.length;i++ ){
					var targetIdMode = $(itemL1[i]).children().attr('id')+'d';
	
					if(targetId != targetIdMode){
						
						$(itemL1[i]).children().attr('class','');
						$('#'+targetIdMode).css('display','none');
					}
				}
	
			}

		});
	
	}
});


  </script>
</html>

